package calculator.controller;/*
 * @author     ：zhangbo
 * @date       ：Created in 2021/5/22 11:56
 * @description：处理用户单击数字按钮触发的ActionEvent事件。
 * @modified By：zhangbo
 * @version:     $
 */

import calculator.view.CalculatorWindows;

import javax.swing.*;
import java.awt.event.ActionEvent;

public class HandleDigit extends HandleEvent {

    public HandleDigit(CalculatorWindows window) {
        super(window);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton b = (JButton) e.getSource();
        String buttomName = b.getText().trim();
        char digit = buttomName.charAt(0);
        window.computer.setDataItem(digit);
        showMess();
        if (digit == '.') {
            String s = get(window.computer.computerDataItem());
            window.showDataItem.setText(" " + s + ".");
        }
    }

}
